Issue #5 and Issue #24

Fixed the bugs of the upper mentioned issues