Added comments and general code clean-up