fixed bug and successfully tested!