Edited function. Working build