Structed the code better