Fixed removing handlers

Object.keys may throw exception.