refactored and big fix p 7 js