Refatoring: basic operations as separate functions