Improving initialization; wait for ready state.

1. Manual merge of update from SlashDevin.
2. Cleanup of code structure.