Refactored a few things, reduced redundancy