Fixed issues found by Will Johansson