Refactored hack into pretty hack