add check_status function, remove dup code