more accurate implementation of std + fixes