Refactored a bunch of code. Much prettier now.