Fixed segfault on EOF and replaced build.sh with makefile