code refining + minor fixes