fixed bug in listening function