refactored notes controller to reduce duplicated code