Added module _on_load and _on_unload functions, and markov chaining