Fixed style and added detailed comments