cleaning up the logic