Adding IO functionality and fixing