cleanup code in GameLayer.js by dissolving some codes into separate function