cleaned code a bit
fixed a bug