Small rewrite and added util functions