some comments added and code clean up