Most of the code should be here