Reorganize the code a little