fixed extremely ugly code