fixed multiple bugs, fixed #1