refactored to support the winforms