Moved memory related function to seperate file