Cleaner code

Not perfect, but much much better