Added headers, cleaned up logic