Formatted a lot of code properly and added some tests