Add exception checking
Change tests according to func changes
Add comments
Add exception checking