Fixed issues (please see commit comment)