added comments
moved code fragments