Working implementation, minimal error checking