It works now, even the code is still very ugly