Fixed several bugs, closed #122, closed #111