First working version of both functions.