Updated motion sensor (more comments, fixed code style a little).