changed if loops rd etc