Refactor: functions grouped properly