code cleanup
WIP: port parts from JSVecX by Chris Smith alias raz0red