First pass at a refactor, doesn't error but doesn't run right