Moved heavy lifting to javascript