feature #3175: Fix bugs
feature #3175: Fix minor bugs. Add simple test