Replaced sleep() with spawn()

A redundant code bit was also removed