Refactoring of renderer.js

Function from renderer.js used in index.js