fixed multiple bugs, fixed #16