Moving procedures into seperate functions for later using.
Fixing horizon detection algorithm, lines uniting algorithms etc.