Added comments and fixed code styling