Fixed bug and added test to avoid any future regression