Added comments explaining the implementation.