Updated code

* Moved files to library
* Simplified and updated code