Basic formatting applied. Unnecessary comments have been removed. Suspicious code is covered by TODO.