Reorganized code a bit more