made the code more pretty and added more comments