Rectangle code refactored