implemented but crashes VC++ optimizer :'(