Refactored a bit, added a Host class and got rid of some ugly code.