improved sensor code