cleaned code for redability and fixed non completion bug