Refactoe ws