More fixes and tested inside an application. More tests to do still