Some restruturing in code