fixed issue #1 and small bugs so it can run