Fixed comments and refactored a bit