Clean up and refactor workspace-related code