added some inline documentation for clarity