slight rewrite of code