Added integration test + some fixes