Fixed bad function copied from stack overflow.
Made the delay more realistic
More todos for code analysis