make it fast, and some c++-isms