Changed a little how detection works and added comments.