Refactored compress method into something more organised