Turned process into defined functions