updated regex and improved python formatting