Redid a few things. Made the code a bit more elegant