reworked js part 3.2

includes cleaned up code and formatting