Added input conditions to all functions