Refactored a lot of suff. Functions are in a lib class now