correctly handle reallocations, flesh out more device handling functions