Removing duplicate code

Untested, but should work.