added routines from best kaggle entry