cleaning up code, adding helper function to mlutil