polished the code a bit more and added a unit test based on a user forum reported issue