buggy as fuck code bastard 3d arrays!