Moved GD related code into separate file