Ermmm, refactoring, changed some things, still looking for better way to organize it