unit and functional tests fixed + some bugs removed