Revamped a lot of code