Added swap
Optimized code criterion
Optimized code calculate results
Added error enum
Added error processing