Fixed checkstyle errors + some bug fixing