Logic refactor

Done.