Fix some bugs; improve code