consider creating pure c functions for this kind of helper methods.