Added comments and debugging logging