code exactly as mikedory #2
renaming #2
small fixes for #2