cleaning code and fixes bug