Fixed some bugs in issues #11 #12