Updated with latest changes from working codebase