fixed bug with functions assignment and added valid id check