Fixed issues (please see commit comments)