utility function for generating, transforming and checking weights