Implement helper functions and weighting