Added a missing unit-test and fixes based on scrutinizer