some code cleaning and functions work, pre tested in console