Reformatted code entirely and made using the script as class possible