Added comments and updated code style