adding test and fixing bug