Made the build script a bit better

Moved some stuff into functions and removed redundant stuff