added .h interface and several other minor changes, also added structs