Some code cleanup, some comments added