Some minor tweaking and refactoring to increase compatibility