Refactored code as a static library
Also added some cmake dependency code