Adding in a few changes to make it a library. Still need to fix up the makefile though