slightly cleaned code