Cleaned up some of the logic
Moved helper method into package