Added comments, minor refactor