Added comments and cleaned code

Added comments and cleaned code