Refactored out dublicate code