Added pause feature, re-fractured code