Added range for output data. Fixed simple bugs