Fixes a number of issues

#47, #82, #44