changed order of def and functions to
match current code base and fixed history