move complex conditions to helper methods in utils
address code review comments