Fixed #49, #17, #46 (hopefully)