Refactored everything a little bit. might be a smidge prettier