Very old and probably bad code done in uni. Might be helpful to someone, so I decided to keep it public.