Added STL use; fixed a few bugs