written in some horrible javascript