refactored but not finished yet