Made the code more class-y
Some changes to make it work again properly