Works fine but need to refactor the code....