Issue fixes

This PR fixes all issues I have opened. Note: I have not tested this code at all.