Added full write/read functionality. Renamed and moved functions to appropriate files.