Overhauled it to fix bugs