working cleaned code