Fixed bug in set x-axis method and simplified some code