Edited to function