Keyfile support and overall refactor