Started hacking at a cleaner version