Fixed bug and added test