some progress; cleaned code a bit