Added sessions and cleaned code a bit