Bug fixes, cleaning the code and updated build script