Much cleaner implementation