Fixed #38, #49 and removed some debug messages