Add comments and general refactoring