Stylistic changes and adding comments

Added comments to some parts of the code. Made sure that usage of {} is consistent with style guidelines.