prototype.cpp - bug fixes, though, still buggy