Cleaned up a bit

rewrote code