Cleaned code

Cleaned code and added more comments