Use read lock when obtaining handlers.
Separate code into separate files.

Added error handling for representation generation.