Cleaner

Cleaned up code with common functions