Refactor Mikes code