More generic functions using arrays instead of single variables