Moving logic to function/Adding tests