Fixed code style and added some extra comments