Reorganized the code and added WS