Added functionality and while loop cancelling