Style improvements, adding comments, renaming methods for clarity