removed some duplicate lines of code and moved a few things around