added key loading and main() functions