Fix some bugs with the implementation.