fix #1 and other arising bugs