Edited functions to make them work