Fixed indentation, added more wait loops instead of pre-scripted key sequences.