ticket:3 with test and fixes