Refactor

Please review and merge