Cleanup, refactor and some comments added.