cleaned code to facilate reuse