Fixed bugs and issue #1