added training and cleaned up recognition