Ugly Code :P, refactoring needed