Fixed issue #39 and some other issues that arised