fix bug and added test to prevent it