fixing toplevel function