updated trim logic based on code review