Rearrange code structure

**WARNING**
DON'T LOOK AT THIS COMMIT!
IT WILL HURT YOUR EYE!