split function further and add test