Moved prepare code to common handler

Added ability to change repo preferences file.
Yes, it was duplicated. It should have been removed months ago.