Removed some repeated code and cleaned up function signatures