Fixed deadline expiration of task that are pending.. and added tests