More math stuff, add Application class, refactor some stuff.