error checking!
merged error checking + debug print