Adding IO functionality,fixing some details