still has errors, but a cleaner solution