Added integration test and fixed crash