cleaning up and unifying code