Cleaned up function code

Cleaned up functions